﻿#define _CRT_SECURE_NO_WARNINGS  1
#include"Queue.h"
#if 0




#include<stdio.h>

int main()
{
    int  a = 0;
    scanf("%d", &a);
    int b = a / 100000;
    if (b == 1)
        printf("Hunan Agricultural University");
    else if (b == 2)
        printf("Jishou University");
    else if (b == 3)
        printf("Huaihua University");
    else if (b == 4)
        printf("Aerospace University");
    else if (b == 5)
        printf("Ocean University");
    else
        printf("Other University");

    return 0;
}

#include<stdio.h>

int main()
{
    int a = 0;
    int b = 0;
    char c = 0;
    scanf("%d %c %d", &a, &c, &b);
    if (c == 43)
        printf("%d", a + b);
    else if (c == 45)
        printf("%d", a - b);
    else if (c == 42)
        printf("%d", a * b);
    else if (c == 47)
        printf("%d", a / b);
    else if (c == 37)
        printf("%d", a % b);
    else
        printf("ERROR");
    return 0;
}
#include<stdio.h>

int main()
{
    int a = 0;
    scanf("%d", &a);
    if (a >= 90)
        printf("A");
    else if (a < 90 && a >= 80)
        printf("B");
    else if (a < 80 && a >= 70)
        printf("C");
    else if (a < 70 && a >= 60)
        printf("D");
    else
        printf("E");

    return 0;
}

#include<stdio.h>

int main()
{
    int arr1[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
    int arr2[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
    int year = 0;
    int month = 0;
    int day = 0;
    scanf("%d/%d/%d", &year, &month, &day);
    int days = 0;
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
    {
        for (int i = 1; i < month; i++)
        {
            days += arr2[i];
        }
        days += day;
        printf("%d", days);
    }
    else
    {
        for (int i = 1; i < month; i++)
        {
            days += arr1[i];
        }
        days += day;
        printf("%d", days);

    }


    return 0;
}




#include<stdio.h>

int main()
{
    char arr[80] = "0";
    gets(arr);
    char* p = arr;
    while (*p != '\0')
    {
        if (*p >= 65 && *p <= 90)
        {
            *p = 155 - *p;
        }
    }

    printf("%s", arr);

    return 0;

}

#include<stdio.h>

int main()
{
    char c;

    //获取输入
    while ((c = getchar()) != '\n')
    {
        if (c <= 90 && c >= 65)
            c = 155 - c;
        putchar(c);
    }

    return 0;
}



#include<stdio.h>

//求阶乘函数
int fuc1(int t)
{
    if (t == 0)
        return 1;
    else
        return t * fuc1(t - 1);

}
//求组合数函数
int fuc2(int i, int j)
{
    if (j == 0)
        return 1;
    else
    {
        if (j < i - j)
            j = i - j;
        return fuc1(i) / fuc1(j);
    }
}

int main()
{
    int info = 0;
    scanf("%d", &info);
    for (int i = 0; i < info; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            printf("%4d", fuc2(i, j));
        }
        //打印完一行后换行
        printf("\n");

    }

    return 0;
}

​
#include<stdio.h>

int main()
{
    int  i;
    scanf("%d", &i);
    if (i < 0)//三种情况
        printf("sign(%d) = -1", i);
    else if (i == 0)
        printf("sign(%d) = 0", i);
    else
        printf("sign(%d) = 1", i);

    return 0;
}

​#include<stdio.h>

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    //因为有可能分数位需要借位，所以分两种情况
    if (b % 100 >= a % 100)
    {
        printf("%02d", (b - a) / 100);
        printf(":%02d", (b - a) % 100);
    }
    else
    {
        printf("%02d", (b - a - 1) / 100);
        printf(":%02d", (b % 100 + 60) - a % 100);//借位
    }
    return 0;
}

#include<stdio.h>

int main()
{
    float a;
    scanf("%f", &a);
    if (a == 10.0)
        printf("f(10.0) = 0.1");
    else
        printf("f(%.1f) = %.1f", a, a);

    return 0;
}
#include<stdio.h>

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d + %d = %d\n", a, b, a + b);
    printf("%d - %d = %d\n", a, b, a - b);
    printf("%d * %d = %d\n", a, b, a * b);
    printf("%d / %d = %d\n", a, b, a / b);

    return 0;
}

#include<stdio.h>

int main()
{
    int  i;
    scanf("%d", &i);
    if (i < 0)//三种情况
        printf("sign(%d) = -1", i);
    else if (i == 0)
        printf("sign(%d) = 0", i);
    else
        printf("sign(%d) = 1", i);

    return 0;
}

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
    struct ListNode* newhead = malloc(sizeof(struct ListNode));
    newhead->next = list1;
    struct ListNode* pcur1 = newhead;
    //只要涉及两个对象将一个放到另一个中，及一定有一个到头另一个还没到的两种情况

    while (pcur1->next)//有两个就说明，有两种走到头的方式 
    {
        if (!list2)
        {
            list2 = newhead->next;
            break;
        }
        if (pcur1->next->val >= list2->val)
        {
            struct ListNode* tmp = pcur1->next;
            pcur1->next = list2;
            list2 = tmp;
        }
        pcur1 = pcur1->next;
        if (!pcur1->next)
        {
            pcur1->next = list2;
            list2 = newhead->next;
            break;
        }
    }


    return list2;
}

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {
    struct ListNode* newhead = malloc(sizeof(struct ListNode));
    newhead->next = list1;
    struct ListNode* pcur1 = newhead;
    //只要涉及两个对象将一个放到另一个中，及一定有一个到头另一个还没到的两种情况

    while (pcur1->next)//有两个就说明，有两种走到头的方式 
    {
        if (!list2)
        {
            list2 = newhead->next;
            break;
        }
        if (pcur1->next->val >= list2->val)
        {
            struct ListNode* tmp = pcur1->next;
            pcur1->next = list2;
            list2 = tmp;
        }
        pcur1 = pcur1->next;
        if (!pcur1->next)
        {
            pcur1->next = list2;
            list2 = newhead->next;
            break;
        }
    }


    return list2;
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) {

    if (!list1 || !list2)
    {
        if (list1)
        {
            list1->next = mergeTwoLists(list1->next, list2);
            return list1;
        }
        else if (list2)
        {
            list2->next = mergeTwoLists(list1, list2->next);
            return list2;
        }
        else
            return NULL;
    }

    else
    {
        if (list1->val >= list2->val)
        {
            list2->next = mergeTwoLists(list1, list2->next);
            return list2;
        }
        else
        {
            list1->next = mergeTwoLists(list1->next, list2);
            return list1;
        }
    }
}

/**
 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
 *
 *
 * @param n int整型
 * @param m int整型
 * @return int整型
 */

 //创建节点
#include <stdlib.h>
struct ListNode* create(int n)
{
    struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
    newnode->val = n;
    return newnode;
}

//创建带环链表
struct ListNode* create_(int n)
{
    struct ListNode* head = create(1);
    struct ListNode* pcur = head;
    for (int i = 2; i <= n; i++)
    {
        pcur->next = create(i);
        pcur = pcur->next;
    }
    pcur->next = head;
    return pcur;

}
int ysf(int n, int m)
{
    // write code here
    struct ListNode* ptail = create_(n);
    while (ptail->next != ptail)
    {
        for (int i = 0; i < m - 1; i++)
        {
            ptail = ptail->next;
        }
        ptail->next = ptail->next->next;
    }
    return ptail->next->val;
}


/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};*/
#include <cstdlib>
class PalindromeList {
public:

    ListNode* Findmid(ListNode* A)
    {
        ListNode* slow, * fast;
        slow = fast = A;
        if (!fast && !slow)
            return NULL;
        while (fast && fast->next)
        {
            fast = fast->next->next;
            slow = slow->next;
        }
        return slow;
    }

    struct ListNode* reverseList(struct ListNode* head)
    {
        ListNode* p2, * p3;
        p2 = head;
        if (!head)
            return NULL;
        p3 = p2->next;
        ListNode* tmp = NULL;
        while (p3)
        {
            p2->next = tmp;
            tmp = p2;
            p2 = p3;
            p3 = p3->next;

        }
        p2->next = tmp;
        return p2;
    }

    bool chkPalindrome(ListNode* A) {
        // write code here
        if (!A)
            return false;
        struct ListNode* mid = Findmid(A);
        struct ListNode* rmid = reverseList(mid);
        struct ListNode* tmp = A;
        while (rmid && tmp)
        {
            if (rmid->val != tmp->val)
                return false;
            rmid = rmid->next;
            tmp = tmp->next;
        }

        return true;
    }
};

/**
 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
 *
 *
 * @param n int整型
 * @param m int整型
 * @return int整型
 */

 //创建节点
#include <stdlib.h>
struct ListNode* create(int n)
{
    struct ListNode* newnode = (struct ListNode*)malloc(sizeof(struct ListNode));
    newnode->val = n;
    return newnode;
}

//创建带环链表
struct ListNode* create_(int n)
{
    struct ListNode* head = create(1);
    struct ListNode* pcur = head;
    for (int i = 2; i <= n; i++)
    {
        pcur->next = create(i);
        pcur = pcur->next;
    }
    pcur->next = head;
    return pcur;

}
int ysf(int n, int m)
{
    // write code here
    struct ListNode* ptail = create_(n);
    while (ptail->next != ptail)
    {
        for (int i = 0; i < m - 1; i++)
        {
            ptail = ptail->next;
        }
        ptail->next = ptail->next->next;
    }
    return ptail->next->val;
}


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    int count1, count2, count;
    count = count1 = count2 = 0;
    struct ListNode* p1, * p2;
    p1 = headA;
    p2 = headB;
    if (!p1 || !p2)
        return NULL;

    while (p1)
    {
        count1++;
        p1 = p1->next;
    }
    while (p2)
    {
        count2++;
        p2 = p2->next;
    }
    struct ListNode* shortlist = headA, * longlist = headB;
    count = abs(count1 - count2);
    if (count1 > count2)
    {
        shortlist = headB;
        longlist = headA;
    }
    while (longlist && count)
    {
        longlist = longlist->next;
        count--;
    }

    while (shortlist && longlist)
    {
        if (longlist == shortlist)
            return longlist;
        longlist = longlist->next;
        shortlist = shortlist->next;
    }
    return NULL;

}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* detectCycle(struct ListNode* head) {
    struct ListNode* slow, * fast;
    fast = slow = head;
    while (fast && fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
        if (fast == slow)
            break;
    }
    slow = head;
    if (!fast || !fast->next)
        return NULL;
    while (fast != slow)
    {
        fast = fast->next;
        slow = slow->next;
    }
    return fast;

}
#include<stdio.h>

int main()
{
    //T-t
    int t = 0;
    scanf("%d", &t);
    while (t--)//循环t次，处理t个矩阵
    {
        int n = 0;
        scanf("%d", &n);
        int arr[n][n];//这是变长数组不能初始化
        int judge = 1;//判断因子

        //输入数组数据
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                scanf("%d ", &arr[i][j]);
                if ((i >= 1 && i <= n - 1) && (j <= i - 1) && (arr[i][j] != 0))//判断赋值
                    judge = 0;
            }
        }

        if (judge)
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}
#include<stdio.h>

//求阶乘函数
int fuc1(int t)
{
    if (t == 0)
        return 1;
    else
        return t * fuc1(t - 1);

}
//求组合数函数
int fuc2(int i, int j)
{
    if (j == 0)
        return 1;
    else
    {
        if (j < i - j)
            j = i - j;
        return fuc1(i) / fuc1(j);
    }
}

int main()
{
    int info = 0;
    scanf("%d", &info);
    for (int i = 0; i < info; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            printf("%4d", fuc2(i, j));
        }
        //打印完一行后换行
        printf("\n");

    }

    return 0;
}
#include<stdio.h>

//求阶乘函数
int fuc1(int t)
{
    if (t == 0)
        return 1;
    else
        return t * fuc1(t - 1);

}
//求组合数函数
int fuc2(int i, int j)
{
    if (j == 0)
        return 1;
    else
    {
        if (j < i - j)
            j = i - j;
        return fuc1(i) / fuc1(j);
    }
}

int main()
{
    int info = 0;
    scanf("%d", &info);
    for (int i = 0; i < info; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            printf("%4d", fuc2(i, j));
        }
        //打印完一行后换行
        printf("\n");

    }

    return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{
    char arr1[10] = "\0";
    scanf("%s", arr1);
    char* p [5] = { "red","blue","yellow","green","black" };
    char* ps = *p;
    int i = 0;
    while (strncmp(ps, arr1,6) != 0)
    {
        ps +=1;
        i++;
    }
    printf("%d", i);

    return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
    char arr1[10] = "\0";
    scanf("%s", arr1);
    char* p[5] = { "red","blue","yellow","green","black" };
    char* ps = *p;
    int i = 0;
    while (strcmp(ps + i, arr1) != 0)
    {
        ++i;
    }
    printf("%d", i);

    return 0;
}

#include<stdio.h>
#include<string.h>

int main()
{
    char arr1[10] = "\0";
    scanf("%s", arr1);
    char* p[5] = { "red","blue","yellow","green","black" };
    char* ps = *p;
    int i = 0;
 
    printf("%s", p[2]);

    return 0;
}

#include<stdio.h>

int main()
{
    printf("%d", -1 / 2);

    return 0;
}
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Note: The returned array must be malloced, assume caller calls free().
  */

void fuc(struct TreeNode* root, int* a, int* i)
{
    if (!root)
        return;
    a[*i] = root->val;
    (*i)++;
    fuc(root->left, a, i);
    fuc(root->right, a, i);
}
int returnsize(struct TreeNode* root)
{
    return !root ? 0 : returnsize(root->left) + returnsize(root->right) + 1;
}

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    *returnSize = returnsize(root);
    int* a = (int*)malloc(sizeof(int) * *returnSize);
    int i = 0;
    fuc(root, a, &i);

    return a;
}

#include<stdio.h>
#include<stdlib.h>
typedef struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    
}TN;
void fuc(struct TreeNode* root, int* a, int* i)
{
    if (!root)
        return;
    a[(*i)++] = root->val;
    fuc(root->left, a, i);
    fuc(root->right, a, i);
}
int returnsize(struct TreeNode* root)
{
    return !root ? 0 : returnsize(root->left) + returnsize(root->right) + 1;
}

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    *returnSize = returnsize(root);
    int* a = (int*)malloc(sizeof(int) * *returnSize);
    int i = 0;
    fuc(root, a, &i);

    return a;
}
//||||||||||||||||||||||||||||||||||||||||
//||||||||||||||||||||||||||||||||||||||||
//||||||||||||||||||||||||||||||||||||||||
//手搓二叉树
int main()
{
    TN* treenode1 = (TN*)malloc(sizeof(TN));
    TN* treenode2 = (TN*)malloc(sizeof(TN));
    TN* treenode3 = (TN*)malloc(sizeof(TN));
    TN* treenode4 = (TN*)malloc(sizeof(TN));

    treenode1->val = 1;
    treenode2->val = 2;
    treenode3->val = 3;
    treenode4->val = 4;
    
    treenode1->left = NULL;
    treenode1->right = treenode2;
    treenode2->left = treenode3;
    treenode2->right = NULL;
    treenode3->left = NULL;
    treenode3->right = NULL;
    int returnSize = 0;
    preorderTraversal(treenode1, &returnSize);

    return 0;
}


// 0

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
#include<stdio.h>
#include<stdlib.h>

struct ListNode {
    int val;
    struct ListNode* next;
};

struct ListNode* reverseList(struct ListNode* head) {

    static struct ListNode* tmp1 = NULL;
    if (!head)
        return tmp1;
    else if (head->next)
    {
        struct ListNode* tmp2 = head->next;
        head->next = tmp1;
        tmp1 = head;
        return reverseList(tmp2);
    }
    else
    {
        head->next = tmp1;
        tmp1 = NULL;
        return head;
    }
}

int main()
{
    struct ListNode* node1 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* node2 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* node3 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* node4 = (struct ListNode*)malloc(sizeof(struct ListNode));

    node1->val = 1;
    node2->val = 2;
    node3->val = 3;
    node4->val = 4;

    node1->next = node2;
    node2->next = node3;
    node3->next = node4;
    node4->next = NULL;

    struct ListNode* p = reverseList(node1);



    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct {
    int k;
    int* a;
    int head;
    int tail;
} MyCircularQueue;

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->head == obj->tail;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return (obj->tail + 1) % (obj->k + 1) == obj->head;
}

MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    obj->a = (int*)malloc(sizeof(int) * (k + 1));
    obj->k = k;
    obj->head = obj->tail = 1;
    return obj;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
        return false;

    obj->a[obj->tail] = value;
    obj->tail = (obj->tail + 1) % (obj->k + 2);
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;

    obj->head = (obj->head + 1) % (obj->k + 1);
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;

    return obj->a[obj->head];
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;

    return obj->a[obj->tail];
}


void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->a);
    obj->a = NULL;
    obj->head = obj->tail = obj->k = 0;
    free(obj);
    obj = NULL;
}


int main()
{
    myCircularQueueCreate(3);


    return 0;
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);

 * bool param_2 = myCircularQueueDeQueue(obj);

 * int param_3 = myCircularQueueFront(obj);

 * int param_4 = myCircularQueueRear(obj);

 * bool param_5 = myCircularQueueIsEmpty(obj);

 * bool param_6 = myCircularQueueIsFull(obj);

 * myCircularQueueFree(obj);
*/




typedef struct {
    int k;
    int* a;
    int head;
    int tail;
} MyCircularQueue;

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->head == obj->tail;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return (obj->tail + 1) % (obj->k + 1) == obj->head;
}

MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    obj->a = (int*)malloc(sizeof(int) * (k + 1));
    obj->k = k;
    obj->head = obj->tail = 1;
    return obj;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
        return false;

    obj->a[obj->tail] = value;
    obj->tail = (obj->tail + 1) % (obj->k + 1);
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;

    obj->head = (obj->head + 1) % (obj->k + 1);
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;

    return obj->a[obj->head];
}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return -1;

    return obj->tail == 0 ? obj->a[obj->k] : obj->a[obj->tail - 1];
}


void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->a);
    obj->a = NULL;
    obj->head = obj->tail = obj->k = 0;
    free(obj);
    obj = NULL;
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);

 * bool param_2 = myCircularQueueDeQueue(obj);

 * int param_3 = myCircularQueueFront(obj);

 * int param_4 = myCircularQueueRear(obj);

 * bool param_5 = myCircularQueueIsEmpty(obj);

 * bool param_6 = myCircularQueueIsFull(obj);

 * myCircularQueueFree(obj);
*/




#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

typedef struct Q {
    struct Q* next;
    int data;
} Queuenode;


typedef struct {
    int size;
    int capacity;
    Queuenode* head;
    Queuenode* tail;

} MyCircularQueue;

bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->size == 0;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    return obj->size == obj->capacity && obj->size != 0;
}

MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* obj = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    obj->size = 0;
    obj->capacity = k;

    obj->tail = obj->head = (Queuenode*)malloc(sizeof(Queuenode));
    obj->head->data = 0;
    Queuenode* pcur = obj->head;
    k--;
    while (k--)
    {
        pcur->next = (Queuenode*)malloc(sizeof(Queuenode));
        pcur->next->data = 0;
        pcur = pcur->next;
        if (k == 0)
            pcur->next = obj->head;
    }
    return obj;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
        return false;
    obj->size++;
    obj->tail->data = value;
    obj->tail = obj->tail->next;
    return true;
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
        return false;

    obj->size--;
    obj->head = obj->head->next;
    return true;
}

int myCircularQueueFront(MyCircularQueue* obj) {
    return obj->head->data;
}

int myCircularQueueRear(MyCircularQueue* obj) {

    return obj->tail->data;
}



void myCircularQueueFree(MyCircularQueue* obj) {


    while (obj->size)
    {
        Queuenode* tmp = obj->head;
        obj->head = obj->head->next;
        free(tmp);
        obj->size--;
    }
    obj->capacity = 0;
    free(obj);
}
//错误
// void myCircularQueueFree1(MyCircularQueue* obj) {
//
//
//    while (obj->head != obj->tail)
//    {
//        Queuenode* tmp = obj->head;
//        obj->head = obj->head->next;
//        free(tmp);
//    }
//    obj->capacity = obj->size = 0;
//    free(obj);
//}
int main()
{
    MyCircularQueue* q = myCircularQueueCreate(3);
    myCircularQueueEnQueue(q, 1);
    myCircularQueueEnQueue(q, 2);
    myCircularQueueEnQueue(q, 3);
    printf("rear:%d\n", myCircularQueueRear(q));

    myCircularQueueFree(q);

    return 0;
}

/**
 * Your MyCircularQueue struct will be instantiated and called as such:
 * MyCircularQueue* obj = myCircularQueueCreate(k);
 * bool param_1 = myCircularQueueEnQueue(obj, value);

 * bool param_2 = myCircularQueueDeQueue(obj);

 * int param_3 = myCircularQueueFront(obj);

 * int param_4 = myCircularQueueRear(obj);

 * bool param_5 = myCircularQueueIsEmpty(obj);

 * bool param_6 = myCircularQueueIsFull(obj);

 * myCircularQueueFree(obj);
*/




#include<stdio.h>
#include<string.h>

int main()
{
    char arr[100];
    char* a = arr;
    gets(arr);
    while (*a != '\0')
    {
        if (*a != 'a')
            printf("%c", *a);
        a++;
    }


    return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
    int i = 0;
    scanf("%d", &i);
    while (i--)
    {
        char* p[7] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
        char a[10];
        scanf("%s",a);
        for (int i = 0; i < 7; i++)
        {
            if (strcmp(a, p[i]) == 0)
            {
                printf("%d\n", i + 1);
                break;
            }
            else if (i == 6)
            {
                printf("-1\n");
            }
        }

    }
    return 0;


#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
int count;

int SearchMid(int *a,int left, int right)
{
    int mid = (left + right) / 2;
    if (a[right] + a[mid] - a[left] * 2 >= 0)
        return left;
    if (a[left] + a[mid] - a[right] * 2 >= 0)
        return right;
    if (a[right] + a[left] - a[mid] * 2 >= 0)
        return mid;


}

void swap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void QuickSort(int * a,int left,int right)
{
    if (right <= left)
        return;

    int begin = left;
    int key = left;
    int end = right;
    while (begin < end)
    {
        count++;
        while (a[end]>=a[key]&& begin < end)
        {
            end--;
        }
        while (a[begin]<=a[key] && begin < end)
        {
            begin++;
        }
        swap(&a[end], &a[begin]);
    }
    swap(&a[end], &a[key]);
    QuickSort(a, key, end - 1);
    QuickSort(a, end + 1,right);

}


void TestQuickSort()
{
    int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
    QuickSort(a, 0, 9);
    printf("%d", count);

}


int main()
{
    TestQuickSort();
    return 0;
}

}


/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
bool isUnivalTree(struct TreeNode* root) {
    if (!root)
        return true;

    if (root->left)
        if (root->val != root->left->val)
            return false;

    if (root->right)
        if (root->val != root->right->val)
            return false;

    bool left = isUnivalTree(root->left);
    bool right = isUnivalTree(root->right);
    return left && right;

}

bool isUnivalTree(struct TreeNode* root) {

    if (!root)
        return true;
    bool a = true, b = true;
    if (root->right)
        a = root->right->val == root->val ? isUnivalTree(root->right) : false;

    if (root->left)
        b = root->left->val == root->val ? isUnivalTree(root->left) : false;

    return a && b;
}






bool isSymmetric(struct TreeNode* root) {
    if (root->left == NULL && root->right == NULL);
    return true;

    if (!root->left || !root->right)
        return false;

    // if(root->left->val!=root->right->val)
    //     return false;

    //return isSymmetric(root->left)&&isSymmetric(root->right);
}

#include<stdio.h>
typedef struct stu
{
    int num;
    char name[10];
    float grade;

}stu;

void Sort(stu* arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (arr[j].grade < arr[j + 1].grade)
            {
                float tmp = arr[j].grade;
                arr[j].grade = arr[j + 1].grade;
                arr[j + 1].grade = tmp;
            }
        }
    }
}

int main()
{
    int j = 0;
    scanf("%d", &j);
    stu arr[j];
    for (int i = 0; i < j; i++)
    {
        int a, b, c;
        scanf("%d %s", &arr[i].num, arr[i].name);
        scanf("%d %d %d", &a, &b, &c);
        arr[i].grade = (a + b + c) / 3.0;
    }
    Sort(arr, j);

    for (int i = 0; i < j; i++)
    {
        printf("%d,%s,%.2f\n", arr[i].num, arr[i].name, arr[i].grade);
    }
    return 0;
}
#include<stdio.h>

int main()
{
    int hour, minute, second;
    scanf("%d:%d:%d", &hour, &minute, &second);
    int a = 0;
    scanf("%d", &a);
    if (second + a >= 60)
    {
        second = second + a - 60;
        minute++;
    }
    else
        second += a;
    if (minute >= 60)
    {
        hour++;
        minute = 0;
    }
    if (hour == 24)
    {
        hour = 0;
    }
    printf("%02d:%02d:%02d", hour, minute, second);



    return 0;
}#include<stdio.h>
typedef struct stuff
{
    char name[10];
    float money;
}stuff;


int main()
{
    int j = 0;
    scanf("%d", &j);
    stuff arr[j];
    for (int i = 0; i < j; i++)
    {
        float a, b, c;
        scanf("%s", arr[i].name);
        scanf("%f %f %f", &a, &b, &c);
        arr[i].money = a + b - c;
    }
    for (int i = 0; i < j; i++)
    {
        printf("%s %.2f\n", arr[i].name, arr[i].money);
    }

    return 0;
}


#include<stdio.h>

typedef struct stu
{
    char num[5];
    char name[10];
    int grades;
}stu;

int main()
{
    int j = 0;
    scanf("%d", &j);
    stu arr[j];
    int sum = 0;
    for (int i = 0; i < j; i++)
    {
        scanf("%s", arr[i].num);
        scanf("%s", arr[i].name);
        scanf("%d", &arr[i].grades);
        sum += arr[i].grades;
    }
    printf("%.2f\n", sum * 1.0 / j);
    for (int i = 0; i < j; i++)
    {
        if (arr[i].grades < sum * 1.0 / j)
        {
            printf("%s ", arr[i].name);
            printf("%.5s\n", arr[i].num);
        }
    }

    return 0;
}

struct complex multiply(struct complex x, struct complex y)
{
    struct complex new_complex;

    new_complex.real = x.real * y.real - x.imag * y.imag;
    new_complex.imag = x.real * y.imag + y.real * x.imag;

    return new_complex;
}
#include<stdio.h>typedef struct stu
{
    int num;
    char name[10];
    float grade;

}stu;

void Sort(stu* arr, int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (arr[j].grade < arr[j + 1].grade)
            {
                stu tmp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = tmp;
            }
        }
    }
}

int main()
{
    int j = 0;
    scanf("%d", &j);
    stu arr[j];
    for (int i = 0; i < j; i++)
    {
        float a, b, c;
        scanf("%d %s", &arr[i].num, arr[i].name);
        scanf("%f %f %f", &a, &b, &c);
        arr[i].grade = (a + b + c) / 3;






#include<stdio.h>
#include<stdlib.h>


        typedef struct Node {
            int data;
            struct Node* next;
        } Node;

        int main()
        {
            int i = 0;

            Node* ptail = NULL;
            Node* phead = NULL;
            while (scanf("%d", &i) && i != -1)
            {
                if (!phead)
                {
                    phead = (Node*)malloc(sizeof(Node));
                    phead->data = i;
                    phead->next = NULL;
                    ptail = phead;
                }
                else
                {
                    ptail->next = (Node*)malloc(sizeof(Node));
                    ptail = ptail->next;
                    ptail->data = i;
                    ptail->next = NULL;
                }

            }
            Node* pcur = phead;
            while (pcur->data % 2 == 0)
            {
                Node* tmp = pcur->next;
                free(pcur);
                pcur = tmp;
            }
            while (pcur->next)
            {
                if (pcur->next->data % 2 == 0)
                {
                    Node* tmp = pcur->next;
                    pcur->next = pcur->next->next;
                    free(tmp);

                }
                pcur = pcur->next;

            }

            while (phead->next)
            {
                if (phead->data % 2 != 0)
                    printf("%d ", phead->data);
                phead = phead->next;
            }
            printf("%d", phead->data);


        }



#include<stdlib.h>
#include<stdio.h>

        typedef struct stud_node
        {
            int num;
            char* name;
            int grade;
            struct stud_node* next;
        }node;

        struct stud_node* Creat_Stu_Doc()
        {
            node* tmp = (node*)malloc(sizeof(node));
            tmp->num = tmp->grade = 0;
            tmp->name = (char*)malloc(sizeof(char) * 8);
            tmp->next = NULL;
            return tmp;
        }

        struct stud_node* DeleteDoc(struct stud_node* head, int min_score)
        {
            while (head->next)
            {
                if (head->next->grade < min_score)
                {
                    node* tmp = head->next->next;
                    free(head->next);
                    head->next = tmp;
                    head = tmp;
                }
                else
                    head = head->next;
            }
        }

        void Print_Stu_Doc(struct stud_node* head)
        {
             while(head)
             {
                 printf("%s %d\n",head->name,head->grade);
                 head = head->next;
             }

        }

        int main()
        {
            int grade = 0;
            int i = 0;
            node* head = NULL;
            node* ptail = NULL;
            while (1)
            {

                scanf("%d", &i);
                if (i == 0)
                    break;
                if (i == 1)
                {
                    head = Creat_Stu_Doc();
                    ptail = head;
                    head->num = i;
                    scanf("%s", head->name);
                    scanf("%d", &head->grade);
                }
                else
                {
                    ptail->next = Creat_Stu_Doc();
                    ptail = ptail->next;
                    ptail->num = i;
                    scanf("%s", ptail->name);
                    scanf("%d", &ptail->grade);
                }

            }
            scanf("%d", &grade);
            node* phead = (node*)malloc(sizeof(node));
            phead->next = head;
            DeleteDoc(phead, grade);
            Print_Stu_Doc(phead->next);

            return 0;
        }




        typedef int QueueDatatype;

        typedef struct QueueNode
        {
            QueueDatatype a;
            struct QueueNode* next;

        }QueueNode;

        typedef struct Queue
        {
            QueueNode* head;
            QueueNode* tail;
            int size;

        }Queue;
        //队列初始化
        void QueueInit(Queue* qp)
        {
            qp->head = qp->tail = NULL;
            qp->size = 0;
        }

        //取队头元素
        QueueDatatype QueueTop(Queue* qp)
        {
            assert(qp);
            assert(qp->size);

            return qp->head->a;
        }

        //队头删除
        void QueuePop(Queue* qp)
        {
            assert(qp);
            assert(qp->size);

            if (qp->size-- == 1)
                qp->tail = NULL;
            QueueNode* tmp = qp->head->next;
            free(qp->head);
            qp->head = tmp;

        }

        //队尾添加
        void QueuePush(Queue* qp, QueueDatatype x)
        {
            assert(qp);
            QueueNode* new_node = (QueueNode*)malloc(sizeof(QueueNode));
            if (!new_node)
            {
                perror("new_node malloc fail!");
                return;
            }
            new_node->next = NULL;
            new_node->a = x;
            if (!qp->head)
                qp->head = qp->tail = new_node;
            else
            {
                qp->tail->next = new_node;
                qp->tail = qp->tail->next;
            }
            qp->size++;
        }


        //队列判空
        bool QueueEmpty(Queue* qp)
        {
            return qp->size == 0;
        }

        //队列销毁
        void QueueDestroy(Queue* qp)
        {
            assert(qp);
            while (!QueueEmpty(qp))
            {
                QueuePop(qp);
            }
        }
        typedef struct {
            Queue* Queue1;
            Queue* Queue2;
        } MyStack;


        MyStack* myStackCreate() {
            MyStack* new_stack = (MyStack*)malloc(sizeof(MyStack));
            new_stack->Queue1 = (Queue*)malloc(sizeof(Queue));
            new_stack->Queue2 = (Queue*)malloc(sizeof(Queue));
            QueueInit(new_stack->Queue1);
            QueueInit(new_stack->Queue2);
            return new_stack;
        }

        void myStackPush(MyStack* obj, int x) {
            QueuePush(obj->Queue1, x);
        }

        int myStackPop(MyStack* obj) {
            int result = obj->Queue1->tail->a;
            QueueNode* tmp = obj->Queue1->head;
            if (obj->Queue1->size == 1)
            {
                QueuePop(obj->Queue1);
            }
            else
            {
                while (tmp->next != obj->Queue1->tail)
                    tmp = tmp->next;
                free(obj->Queue1->tail);
                obj->Queue1->size--;
                obj->Queue1->tail = tmp;
            }

            return result;
        }

        int myStackTop(MyStack* obj) {
            return obj->Queue1->tail->a;
        }

        bool myStackEmpty(MyStack* obj) {
            return QueueEmpty(obj->Queue1);
        }

        void myStackFree(MyStack* obj) {
            if (obj->Queue1)
                QueueDestroy(obj->Queue1);

            free(obj);
            obj = NULL;
        }

        /**
         * Your MyStack struct will be instantiated and called as such:
         * MyStack* obj = myStackCreate();
         * myStackPush(obj, x);

         * int param_2 = myStackPop(obj);

         * int param_3 = myStackTop(obj);

         * bool param_4 = myStackEmpty(obj);

         * myStackFree(obj);
        */

        /**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
        int calculateDepth(struct TreeNode* root) {
            if (!root)
                return 0;

            int left = calculateDepth(root->left);
            int right = calculateDepth(root->right);
            int max = left;
            if (right > left)
                max = right;
            return max + 1;

        }
        /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     struct TreeNode *left;
     *     struct TreeNode *right;
     * };
     */
     /**
      * Note: The returned array must be malloced, assume caller calls free().
      */

        int TreeNodeCalculate(struct TreeNode* root)
        {
            return root ? 1 + TreeNodeCalculate(root->left) + TreeNodeCalculate(root->right) : 0;
        }

        void _preorderTraversal(struct TreeNode* root, int* result, int* num)
        {
            if (!root)
                return;

            result[(*num)++] = root->val;//优先级

            _preorderTraversal(root->left, result, num);
            _preorderTraversal(root->right, result, num);
        }


        int* preorderTraversal(struct TreeNode* root, int* returnSize) {
            *returnSize = TreeNodeCalculate(root);
            int* result = (int*)malloc(sizeof(int) * *returnSize);//sizeof(*returnSize)
            int num = 0;
            _preorderTraversal(root, result, &num);
            return result;
        }
        /**
         * Definition for a binary tree node.
         * struct TreeNode {
         *     int val;
         *     struct TreeNode *left;
         *     struct TreeNode *right;
         * };
         */
         /**
          * Note: The returned array must be malloced, assume caller calls free().
          */
        int calculatenode(struct TreeNode* root)
        {
            return root ? 1 + calculatenode(root->left) + calculatenode(root->right) : 0;
        }

        void _inorderTraversal(struct TreeNode* root, int* arr, int* num)
        {
            if (!root)
                return;
            _inorderTraversal(root->left, arr, num);
            arr[(*num)++] = root->val;
            _inorderTraversal(root->right, arr, num);
        }

        int* inorderTraversal(struct TreeNode* root, int* returnSize) {
            *returnSize = calculatenode(root);
            int* arr = (int*)malloc(sizeof(int) * *returnSize);
            int num = 0;
            _inorderTraversal(root, arr, &num);
            return arr;
        }
        /**
         * Definition for a binary tree node.
         * struct TreeNode {
         *     int val;
         *     struct TreeNode *left;
         *     struct TreeNode *right;
         * };
         */
         /**
          * Note: The returned array must be malloced, assume caller calls free().
          */


        int calculatenode(struct TreeNode* root)
        {
            return root ? 1 + calculatenode(root->left) + calculatenode(root->right) : 0;
        }

        void _postorderTraversal(struct TreeNode* root, int* arr, int* num)
        {
            if (!root)
                return;
            _postorderTraversal(root->left, arr, num);
            _postorderTraversal(root->right, arr, num);
            arr[(*num)++] = root->val;
        }

        int* postorderTraversal(struct TreeNode* root, int* returnSize) {
            *returnSize = calculatenode(root);
            int* arr = (int*)malloc(sizeof(int) * *returnSize);
            int num = 0;
            _postorderTraversal(root, arr, &num);
            return arr;
        }

#include<stdio.h>
#include<stdlib.h>

        typedef struct TreeNode
        {
            char val;
            struct TreeNode* left;
            struct TreeNode* right;
        }TreeNode;

        TreeNode* CreateTree(char* arr, int* num)
        {
            if (arr[(*num)++] == '#')
                return NULL;
            TreeNode* node = (TreeNode*)malloc(sizeof(TreeNode));
            node->val = arr[*num - 1];
            node->left = CreateTree(arr, num);
            node->right = CreateTree(arr, num);

            return node;
        }

        void MidPrint(TreeNode* root)
        {
            if (!root)
                return;
            MidPrint(root->left);
            printf("%c ", root->val);
            MidPrint(root->right);

        }

        int main()
        {
            char arr[100] = "0";
            //  scanf("%s",arr);
            gets(arr);
            int num = 0;
            TreeNode* tree = CreateTree(arr, &num);
            MidPrint(tree);

            return 0;
        }
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<stdbool.h>

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
            
};
typedef struct TreeNode* QueueDatatype;

typedef struct QueueNode
{
    QueueDatatype x;
    struct QueueNode* next;
}QueueNode;

typedef struct Queue
{
    QueueNode* head;
    QueueNode* tail;
    int size;
}Queue;

//队列初始化
void QueueInit(Queue* qp)
{
    assert(qp);
    qp->head = qp->tail = NULL;
    qp->size = 0;
}

//队尾插入
void QueuePush(Queue* qp, QueueDatatype y)
{
    assert(qp);
    QueueNode* node = (QueueNode*)malloc(sizeof(QueueNode));
    if (!node)
    {
        perror("malloc fail!");
        return;
    }
    node->x = y;
    node->next = NULL;
    if (qp->size++ == 0)
        qp->head = qp->tail = node;
    else
    {
        qp->tail->next = node;
        qp->tail = qp->tail->next;
    }
}

//队头删除
void QueuePop(Queue* qp)
{
    assert(qp);
    assert(qp->size);
    if (qp->size-- == 1)
        qp->tail = NULL;
    QueueNode* tmp = qp->head;
    qp->head = qp->head->next;
    free(tmp);
    tmp = NULL;
}

//取队头元素
QueueDatatype QueueTop(Queue* qp)
{
    assert(qp);
    assert(qp->size);
    return  qp->head->x;
}

//队列判空
bool QueueEmpty(Queue* qp)
{
    assert(qp);
    return !qp->size;
}

//队列销毁
void QueueDestroy(Queue* qp)
{
    assert(qp);
    while (!QueueEmpty(qp))
        QueuePop(qp);
}

//统计队列元素个数
int QueueSize(Queue* qp)
{
    assert(qp);
    return qp->size;
}


int** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes) {
    Queue q;
    QueueInit(&q);
    int k;
    QueuePush(&q, root);
    while (!QueueEmpty(&q))
    {
        k = QueueSize;
        int* arr = (int*)malloc(sizeof(int) * k);
        for (int i = 0; i < k; i++)
        {
            struct TreeNode* node = QueueTop(&q);
            QueuePop(&q);
            arr[i] = node->val;

            if (node->left)
                QueuePush(&q, node->left);
            if (node->right)
                QueuePush(&q, node->right);

        }
        int num = sizeof(returnColumnSizes);
        realloc(returnColumnSizes, num + sizeof(arr));
        returnColumnSizes[*returnSize - 1] = arr;

    }

    QueueDestroy(&q);
    return returnColumnSizes;
}

struct TreeNode* BinaryTreeGreate(char * root, int* arr)
{
    if (root[(*arr)++] == '#')//注意返回空arr也要加加
        return NULL;
    struct TreeNode* newnode = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    if (!newnode)
    {
        perror("malloc fail!");
        return;
    }
    newnode->val = root[(*arr) - 1];//*的优先级小于++
    newnode->left = BinaryTreeGreate(root, arr);
    newnode->right = BinaryTreeGreate(root, arr);

    return newnode;
}

int main()
{
    int num1 = 0;
    char arr = "1##";
    struct TreeNode* Tree = BinaryTreeGreate(arr, &num1);
    int num2 = 0;
    int** returnColumnSizes;
    levelOrder(Tree, &num2, returnColumnSizes);
}



#include"Queue.h"

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
};
int TreeNodeHeight(struct TreeNode* root)
{
    if (!root)
        return 0;

    int left = TreeNodeHeight(root->left) + 1;
    int right = TreeNodeHeight(root->right) + 1;
    if (left > right)
        return left;
    return right;
}


int** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes) {
    Queue q;
    QueueInit(&q);
    QueuePush(&q, root);
    *returnSize = TreeNodeHeight(root);
    *returnColumnSizes = (int*)malloc(*returnSize * sizeof(int));
    int** returnColumn = (int**)malloc(*returnSize * sizeof(int*));
    int num = 0;
    while (!QueueEmpty(&q))
    {
        int k = QueueSize(&q);
       *(*returnColumnSizes + num) = k;
        int* arr = (int*)malloc(sizeof(int) * k);
        for (int i = 0; i < k; i++)
        {
            struct TreeNode* node = QueueTop(&q);
            QueuePop(&q);
            arr[i] = node->val;

            if (node->left)
                QueuePush(&q, node->left);
            if (node->right)
                QueuePush(&q, node->right);
        }
        returnColumn[num++] = arr;
    }
    QueueDestroy(&q);
    return returnColumn;
}

int main()
{
    struct TreeNode* node1 = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    struct TreeNode* node2 = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    struct TreeNode* node3 = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    struct TreeNode* node4 = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    struct TreeNode* node5 = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    struct TreeNode* node6 = (struct TreeNode*)malloc(sizeof(struct TreeNode));

    node1->val = 1;
    node2->val = 2;
    node3->val = 3;
    node4->val = 4;
    node5->val = 4;
    node6->val = 4;

    node1->left = node2;
    node1->right = node3;
    
    node2->left = node4;
    node2->right = node5;

    node3->left = node6;
    node3->right = NULL;

    node4->left = NULL;
    node4->right = NULL;

    node5->left = NULL;
    node5->right = NULL;

    node6->left = NULL;
    node6->right = NULL;

    int returnSize = 0;
    int* returnColumnSizes;
    int** arr = levelOrder(node1, &returnSize, &returnColumnSizes);

    free(node1);
    free(node2);
    free(node3);
    free(node4);
    free(node5);
    free(node6);

    return 0;
}
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
 /**
  * Return an array of arrays of size *returnSize.
  * The sizes of the arrays are returned as *returnColumnSizes array.
  * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
  */
typedef struct TreeNode* QueueDatatype;

typedef struct QueueNode
{
    QueueDatatype x;
    struct QueueNode* next;
}QueueNode;

typedef struct Queue
{
    QueueNode* head;
    QueueNode* tail;
    int size;
}Queue;

//队列初始化
void QueueInit(Queue* q)
{
    assert(q);
    q->size = 0;
    q->head = q->tail = NULL;
}

//队尾插入
void QueuePush(Queue* q, QueueDatatype x)
{
    assert(q);
    QueueNode* node = (QueueNode*)malloc(sizeof(QueueNode));
    node->x = x;
    node->next = NULL;
    if (!q->size++)
        q->head = q->tail = node;
    else
    {
        q->tail->next = node;
        q->tail = node;
    }

}

//队头删除
void QueuePop(Queue* q)
{
    assert(q);
    assert(q->size);
    QueueNode* tmp = q->head;
    q->head = q->head->next;
    if (q->size-- == 1)
        q->tail = NULL;
    free(tmp);
    tmp = NULL;

}

QueueDatatype QueueTop(Queue* q)
{
    assert(q);
    assert(q->size);

    return q->head->x;
}

bool QueueEmpty(Queue* q)
{
    assert(q);
    return q->size == 0;
}

void QueueDestroy(Queue* q)
{
    assert(q);
    while (!QueueEmpty(q))
    {
        QueuePop(q);
    }
}

int QueueSize(Queue* q)
{
    assert(q);
    return q->size;
}

int TreeNodeHeight(struct TreeNode* root)
{
    if (!root)
        return 0;

    int left = TreeNodeHeight(root->left);
    int right = TreeNodeHeight(root->right);
    if (left > right)
        return left + 1;

    return right + 1;

}

int** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes) {
    if (!root)
    {
        *returnSize = 0;
        *returnColumnSizes = NULL;
        return NULL;
    }

    int n = TreeNodeHeight(root);
    *returnSize = n;
    *returnColumnSizes = (int*)malloc(sizeof(int) * n);
    int** arr = (int**)malloc(sizeof(int*) * n);
    Queue q;
    QueueInit(&q);
    QueuePush(&q, root);
    for (int m = 0; m < n; m++)
    {
        int o = QueueSize(&q);
        arr[m] = (int*)malloc(sizeof(int) * o);
        (*returnColumnSizes)[m] = o;

        for (int i = 0; i < o; i++)
        {
            struct TreeNode* node = QueueTop(&q);
            QueuePop(&q);
            arr[m][i] = node->val;
            if (node->left)
                QueuePush(&q, node->left);
            if (node->right)
                QueuePush(&q, node->right);
        }
    }
    QueueDestroy(&q);
    return arr;
}
int distributeCandies(int n, int limit) {

    if (3 * limit < n)
        return 0;
    int num1, num2;
    for (num1 = 0; n - num1 > 2 * limit; num1++);
    if (n < limit)
        num2 = n;
    else
        num2 = limit;

    int result = 0;
    if (num1 < num2)
        Swap(&num1, &num2);
    for (int i = num2; i <= num1; i++)
    {
        int num = n - i, num3 = 0;
        while (num - num3 > limit)
            num3++;
        result += 1 + (num - 2 * num3);
    }
    return result;

}

int distributeCandies(int n, int limit) {

    int result = 0;
    for (int i = 0; i <= fmin(limit, n); i++)
    {
        if (n - i > 2 * limit)
            continue;
        result += fmin(n - i, limit) - fmax(0, n - i - limit) + 1;
    }
    return result;

}


#include<stdio.h>
#include<stdlib.h>


int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
    int* returnarr = (int*)malloc(sizeof(int) * 2);
    *returnSize = 2;
    int max = 0, min = 0;
    for (int i = 1; i < numsSize; i++)
    {
        if (nums[max] < nums[i])
            max = i;

        if (nums[min] > nums[i])
            min = i;
    }

    int* tmparr = (int*)calloc(nums[max] - nums[min] + 1, sizeof(int));
    for (int i = 0; i < numsSize; i++)
    {
        tmparr[nums[i] - nums[min]] = i;
    }

    for (int i = 0; i < nums[max] - nums[min] + 1; i++)
    {
        if (tmparr[i] && tmparr[target - i - 2 * nums[min]])
        {
            returnarr[0] = tmparr[i];
            returnarr[1] = target - i - nums[min];
            break;
        }
    }
    // int i =0;
    // returnarr[0] = target-i-2*nums[min];
    // returnarr[1] = target-i-2*nums[min];
    free(tmparr);
    tmparr = NULL;
    return returnarr;
}

int main()
{
    int num[] = { 2,7,11,15 };
    
    int returnSize = 0;
    twoSum(num, 4, 9, &returnSize);


    return 0;
}

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
struct TreeNode* invertTree(struct TreeNode* root) {
    if (!root)
        return NULL;
    invertTree(root->left);
    invertTree(root->right);

    struct TreeNode* tmp = root->left;
    root->left = root->right;
    root->right = tmp;


    return root;
}
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
struct TreeNode* invertTree(struct TreeNode* root) {
    if (!root)
        return NULL;
    invertTree(root->left);
    invertTree(root->right);

    struct TreeNode* tmp = root->left;
    root->left = root->right;
    root->right = tmp;


    return root;


    /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     struct TreeNode *left;
     *     struct TreeNode *right;
     * };
     */
    struct TreeNode* invertTree(struct TreeNode* root) {
        if (!root)
            return NULL;
        invertTree(root->left);
        invertTree(root->right);

        struct TreeNode* tmp = root->left;
        root->left = root->right;
        root->right = tmp;


        return root;
    }
    /**
     * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     struct TreeNode *left;
     *     struct TreeNode *right;
     * };
     */
    struct TreeNode* invertTree(struct TreeNode* root) {
        if (!root)
            return NULL;
        invertTree(root->left);
        invertTree(root->right);

        struct TreeNode* tmp = root->left;
        root->left = root->right;
        root->right = tmp;


        return root;
    }
}



#include<stdio.h>
#include<windows.h>

int main()
{   
    printf("red\n");
    Sleep(3000);
    printf("red\n");

}


#include<string.h>

int FirstNotRepeatingChar(char* str) {
    // write code here
    int a1[52] = { 0 };
    int a2[52] = { 0 };
    int l = strlen(str);
    for (int i = 0; i < 52; i++)
        a2[i] = l;
    char b[52];
    char c1 = 'A';
    int n = 0;
    while (c1 <= 'Z')
    {
        b[n++] = c1++;
    }
    c1 = 'a';
    while (c1 <= 'z')
    {
        b[n++] = c1++;
    }
    char* tmp = str;
    while (*tmp)
    {
        int i = 0;
        for (i = 0; *tmp != b[i]; i++);
        a1[i]++;
        if (a2[i] > tmp - str)
            a2[i] = tmp - str;
        tmp++;

    }
    int j = 1;
    int t1 = tmp - str - 1;
    for (int i = 0; i < 52; i++)
    {
        if (a1[i] == 1 && a2[i] < t1)
        {
            j = 0;
            t1 = a2[i];
        }
    }
    if (j)
        return -1;
    return t1;
}
#include<stdio.h>
int main()
{

    char arr[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
    int n = FirstNotRepeatingChar(arr);
    printf("%d", n);

    return 0;
}


bool CheckPermutation(char* s1, char* s2) {

    int l1 = strlen(s1);
    int l2 = strlen(s2);
    if (l1 != l2)
        return false;
    int c1[26] = { 0 };
    int c2[26] = { 0 };
    for (int i = 0; i < l1; i++)
    {
        c1[*s1++ - 'a']++;
        c2[*s2++ - 'a']++;
    }

    for (int i = 0; i < l1; i++)
    {
        if (c1[i] != c2[i])
            return false;
    }
    return true;
}


int main()
{
    char a1[] = "cuhv";
    char a2[] = "cuvs";
    bool a = CheckPermutation(a1, a2);

    return 0;
}



bool canPermutePalindrome(char* s) {
    int a[26] = { 0 };
    int l = strlen(s);
    for (int i = 0; i < l; i++)
    {
        if (!isalpha(*(s + i)))
            continue;
        a[*(s + i) - 'a']++;
    }
    int t = 0;
    for (int i = 0; i < 26; i++)
    {
        if (a[i] % 2 != 0 && t++ == 1)
            return false;
    }
    return true;

}

int main()
{
    char a[] = "AaBb//a";
    bool c = canPermutePalindrome(a);

    return 0;
}



#include <stdio.h>
#include<string.h>

int main() {
    char arr[20] = "0";
    int n = 0;
    scanf("%d", &n);
    while (n--)
    {
        gets(arr);
        int l = strlen(arr);
        if (l < 10)
            printf("%s\n", arr);
        else
        {
            int i = 0;
            printf("%c", *arr);
            while (arr[i])
            {
                i++;
            }
            printf("%d%c\n", i - 2, arr[i - 1]);
        }

        memset(arr, 0, 20);
    }
    return 0;
}



char* replaceSpaces(char* S, int length) {
    int s1 = strlen(S) - 1;
    int s2 = length - 1;

    while (s2 >= 0)
    {
        if (S[s2] == ' ')
        {
            S[s1--] = '0';
            S[s1--] = '2';
            S[s1--] = '%';
        }
        else
            S[s1--] = S[s2];
        s2--;
    }

    return S + s1 + 1;
}

int main()
{
    char arr[] = "Mr John Smith    ";
    printf("%s", replaceSpaces(arr, 13));

    return 0;
}
#include <stdio.h>

int main()
{
    char sentence[] = "Rudolphis 12";
    char str[20];
    int i = 0;

    sscanf(sentence, "%s %d", str,&i);
    printf("%s -> %d\n", str, i);

    return 0;
}

char* compressString(char* S) {
    int l1 = strlen(S) - 1;
    int l2 = strlen(S) - 1;
    char* tmp = (char*)malloc(l1 + 1);
    memcpy(tmp, S, l1 + 1);
    while (l1 >= 0)
    {
        char c = S[l1];
        int t = 0;
        while (c == S[l1])
        {
            t++;
            l1--;
        }
        while (t)
        {
            S[l2--] = '0' + t % 10;
            t /= 10;
        }
        S[l2--] = c;
    }
    if (strlen(l2 + 1 + S) > strlen(tmp))
        return tmp;
    free(tmp);
    return l2 + 1 + S;
}
char* compressString(char* S) {
    int l1 = strlen(S) - 1;
    int l2 = 2 * strlen(S) - 2;
    char* tmp = (char*)calloc(2 * strlen(S), 1);
    if (!tmp)
    {
        perror("calloc fail!");
        return NULL;
    }
    memcpy(tmp, S, l1 + 1);
    while (l1 >= 0)
    {
        char c = tmp[l1];
        int t = 0;
        while (l1 >= 0 && c == tmp[l1])
        {
            t++;
            l1--;
        }
        while (t)
        {
            tmp[l2--] = '0' + t % 10;
            t /= 10;
        }
        tmp[l2--] = c;
    }
    if (strlen(l2 + 1 + tmp) < strlen(S))
        return l2 + 1 + tmp;
    return S;
}


int main()
{
    char a[] = "a";
    char b[] = "abbccd";
    printf("%s\n", compressString(a));
    printf("%s\n", compressString(b));

    return 0;
}


int exchangeBits(int num) {
    if (!num)
        return num;
    char arr[3];
    int n = 0;
    int _num = num;
    int i = 0;
    for (i = 0; i < 3; i++)
    {
        arr[i] = _num % 2 + '0';
        _num /= 2;
    }

    int x = 0, y = 1;
    while (y < 3)
    {
        char tmp = arr[x];
        arr[x] = arr[y];
        arr[y] = tmp;
        x++, y++;
    }
    unsigned int a = 1;
    for (int j = 0; j < 3; j++)
    {
        _num += (arr[j] - '0') * a;
        a *= 2;
    }
    return _num;
}

int main()
{
    int n = exchangeBits(3);
    printf("%d", n);

    return 0;
}
#include <stdio.h>
#include<stdbool.h>

bool Judge(int n)
{
    if (n % 10 == 7)
        return true;
    if (!n % 10)
        return false;
    return Judge(n / 10);
}

int main() {
    int n = 0;
    int t = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        if (i % 7 == 0)
            t++;
        else if (Judge(i))
            t++;
    }
    printf("%d", t);

    return 0;
}int multiply(int A, int B) {
    if (B == 1)
        return A;
    return multiply(A, B - 1) + A;
}
int f(int n)
{
    int r = 0;
    while (n % 5 == 0)
    {
        n /= 5;
        r++;
    }
    return r;
}

int trailingZeroes(int n) {
    if (!n)
        return 0;
    int t = 0;
    while (n % 5)
    {
        n--;
    }
    while (n)
    {
        t += f(n);
        n -= 5;
    }
    return t;
}
#include <stdio.h>

int main() {
    double a = 0;
    scanf("%lf", &a);
    if ((a - (int)a) >= 0.5)
        a = (int)a + 1;

    printf("%d", (int)a);
    return 0;
}


unsigned long int fuc(unsigned long int a, unsigned long int b, unsigned long int t)
{
    unsigned long int num = 0;
    for (unsigned long int i = 0; i < t - 2; i++)
    {
        num = 2 * b + a;
        a = b;
        b = num;
    }
    return num;
}

int main() {
    int n = 0;
    scanf("%ld", &n);
    while (n--)
    {
        unsigned  num = 0;
        scanf("%ld", &num);
        if (num > 2)
        {
            num = fuc(1, 2, num);
            printf("%ld\n", num % 32767);
        }
        else
        {
            printf("%ld\n", num);
        }
    }

    return 0;
}


struct ListNode {
    int val;
    struct ListNode* next;
};


struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
    struct ListNode* p1 = head;
    struct ListNode* p2 = head;

    while (p2->next && n--)
    {
        p2 = p2->next;
    }
    while (p2->next)
    {
        p1 = p1->next;
        p2 = p2->next;
    }

    struct ListNode* tmp = p1->next;
    p1->next = p1->next->next;
    free(tmp);
    tmp = NULL;

    return head;
}

int main()
{
    struct ListNode* q1 = (struct ListNode*)malloc(sizeof(struct ListNode));
    struct ListNode* q2 = (struct ListNode*)malloc(sizeof(struct ListNode));
    q1->next = q2;
    q2->next = NULL;
    q1->val =21;
    q2->val = 1;
    struct ListNode* q = removeNthFromEnd(q1, 2);

    return 0;
}


/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
    struct ListNode* p1 = head;
    struct ListNode* p2 = head;
    struct ListNode* tmp = NULL;
    while (n-- > -1)
    {
        p2 = p2->next;
        if (n > -1 && !p2)
        {
            tmp = head->next;
            free(head);
            return tmp;
        }
    }

    while (p1 && p2)
    {
        p1 = p1->next;
        p2 = p2->next;
    }
    tmp = p1->next;
    p1->next = p1->next->next;
    free(tmp);
    tmp = NULL;

    return head;

}

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* deleteMiddle(struct ListNode* head) {
    struct ListNode* p1 = head;
    struct ListNode* p2 = head->next;
    if (!p2)
    {
        free(head);
        return NULL;
    }
    while (p2->next && p2->next->next)
    {
        p2 = p2->next->next;
        p1 = p1->next;
    }
    struct ListNode* tmp = p1->next;
    p1->next = p1->next->next;
    free(tmp);
    return head;
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* swapNodes(ListNode* head, int k) {
        struct ListNode* p1 = head;
        struct ListNode* p2 = head;
        struct ListNode* p3 = head;
        int t = k - 1;
        while (t--)
        {
            p1 = p1->next;
        }
        while (k--)
        {
            p3 = p3->next;
        }
        while (p3)
        {
            p3 = p3->next;
            p2 = p2->next;
        }
        swap(p1->val, p2->val);
        return head;
    }
};

int main() {
    unsigned int n = 0;
    scanf("%d", &n);
    unsigned int arr[2];
    unsigned int max = 0;
    for (unsigned int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
        if (arr[i] > max)
            max = arr[i];
    }
    unsigned int array[5284];
    array[0] = 1;
    array[1] = 2;
    for (unsigned int i = 2; i < max; i++)
    {
        array[i] = (array[i - 1] * 2 + array[i - 2]) % 32767;//尽量小
    }
    for (unsigned int i = 0; i < n; i++)
    {
        printf("%d\n", array[arr[i] - 1]);
    }

    return 0;
}



/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* runningSum(int* nums, int numsSize, int* returnSize) {
    int* returnArr = (int*)malloc(sizeof(int) * numsSize);
    *returnSize = numsSize;
    memcpy(returnArr, nums, sizeof(int) * numsSize);
    int tmp = 0;
    for (int i = 0; i < numsSize; i++)
    {
        tmp += returnArr[i];
        returnArr[i] = tmp;
    }
    return returnArr;
}


int main()
{
    int a, b;
    while (scanf("%d %d",&b,&a)!=EOF)
    {
        int m = (4 * b - a) >> 1;
        int n = (a - 2 * b) >> 1;
        if (m < 0 || n < 0)
            printf("No answer\n");
        else    
            printf("%d %d\n", m, n);
    }
    return 0;
}


s.clear();

const int N = 256;
char buff[N];
int i = 0;

char ch;
//in >> ch;
ch = in.get();
while (ch != ' ' && ch != '\n')
{
    buff[i++] = ch;
    if (i == N - 1)
    {
        buff[i] = '\0';
        s += buff;

        i = 0;
    }

    //in >> ch;
    ch = in.get();
}

if (i > 0)
{
    buff[i] = '\0';
    s += buff;
}
const int N = 256;
char buff[N];
int i = 0;

char ch;
//in >> ch;
ch = in.get();
while (ch != ' ' && ch != '\n')
{
    buff[i++] = ch;
    if (i == N - 1)
    {
        buff[i] = '\0';
        s += buff;

        i = 0;
    }

    //in >> ch;
    ch = in.get();
}

if (i > 0)
{
    buff[i] = '\0';
    s += buff;
}
const int N = 256;
char buff[N];
int i = 0;

char ch;
//in >> ch;
ch = in.get();
while (ch != ' ' && ch != '\n')
{
    buff[i++] = ch;
    if (i == N - 1)
    {
        buff[i] = '\0';
        s += buff;

        i = 0;
    }

    //in >> ch;
    ch = in.get();
}

if (i > 0)
{
    buff[i] = '\0';
    s += buff;
}
const int N = 256;
char buff[N];
int i = 0;

char ch;
//in >> ch;
ch = in.get();
while (ch != ' ' && ch != '\n')
{
    buff[i++] = ch;
    if (i == N - 1)
    {
        buff[i] = '\0';
        s += buff;

        i = 0;
    }

    //in >> ch;
    ch = in.get();
}

if (i > 0)
{
    buff[i] = '\0';
    s += buff;
}
const int N = 256;
char buff[N];
int i = 0;

char ch;
//in >> ch;
ch = in.get();
while (ch != ' ' && ch != '\n')
{
    buff[i++] = ch;
    if (i == N - 1)
    {
        buff[i] = '\0';
        s += buff;

        i = 0;
    }

    //in >> ch;
    ch = in.get();
}

if (i > 0)
{
    buff[i] = '\0';
    s += buff;
}
int addDigits(int num) {
    while (num >= 10)
    {
        int n = 0;
        while (num)
        {
            n += num % 10;
            num /= 10;
        }
        num = n;
    }
    return num;
}
int waysToStep(int n) {
    unsigned int arr[4];
    arr[0] = 1, arr[1] = 2, arr[2] = 4;
    if (n <= 3)
        return arr[n - 1];
    while (n - 3 > 0)
    {
        arr[3] = (arr[0] + arr[1] + arr[2]) % 1000000007;
        arr[0] = arr[1], arr[1] = arr[2], arr[2] = arr[3];
        n--;
    }
    return arr[3];
}
bool isUgly(int n) {
    while (n >= 2 && n % 2 == 0)
    {
        n /= 2;
    }
    while (n >= 3 && n % 3 == 0)
    {
        n /= 3;
    }
    while (n >= 5 && n % 5 == 0)
    {
        n /= 5;
    }
    if (n == 1)
        return true;
    return false;
}

int minCostClimbingStairs(int* cost, int costSize) {
    if (costSize == 1 || costSize == 0)
        return 0;
    int a = minCostClimbingStairs(cost, costSize - 1) + cost[costSize - 1];
    int b = minCostClimbingStairs(cost, costSize - 2) + cost[costSize - 2];
    if (a > b)
        return b;
    return a;
}
int minCostClimbingStairs(int* cost, int costSize) {
    int arr[costSize];
    arr[0] = cost[0];
    arr[1] = cost[1];
    for (int i = 2; i < costSize; i++)
    {
        arr[i] = cost[i] + fmin(arr[i - 1], arr[i - 2]);
    }
    return fmin(arr[costSize - 1], arr[costSize - 2]);

}
int minCostClimbingStairs(int* cost, int costSize) {
    int arr[costSize];
    arr[costSize - 1] = cost[costSize - 1], arr[costSize - 2] = cost[costSize - 2];
    for (int i = costSize - 3; i >= 0; i--)
    {
        arr[i] = fmin(arr[i + 2], arr[i + 1]) + cost[i];
    }
    return fmin(arr[0], arr[1]);
    // return arr[1];
}



#endif